package com.service;

import static com.def.GenericDef.BANK_OUT;
import static com.def.GenericDef.EVT_REGIST_LOT;
import static com.def.GenericDef.EVT_WIP_RETAIN;
import static com.def.GenericDef.EVT_WIP_RETAIN_CANCEL;
import static com.def.GenericDef.E_READ_NOT_FOUND;
import static com.def.GenericDef.E_RET_BOX;
import static com.def.GenericDef.E_XPWIPRETAIN_ALREADY_LOT;
import static com.def.GenericDef.E_XPWIPRETAIN_INVALID_BNK_FLG;
import static com.def.GenericDef.E_XPWIPRETAIN_INVALID_BOX_STATUS;
import static com.def.GenericDef.E_XPWIPRETAIN_INVALID_INPUT;
import static com.def.GenericDef.E_XPWIPRETAIN_INVALID_PRD_STATUS;
import static com.def.GenericDef.E_XPWIPRETAIN_INVALID_REAL_EMP;
import static com.def.GenericDef.E_XPWIPRETAIN_INVALID_VALID_FLG;
import static com.def.GenericDef.E_XPWIPRETAIN_NO_LOT;
import static com.def.GenericDef.E_XPWIPRETAIN_NO_PRD_IN_BOX;
import static com.def.GenericDef.E_XPWIPRETAIN_WO_UNMATCH;
import static com.def.GenericDef.LOT_SPLIT_0;
import static com.def.GenericDef.PROC_EMPTY;
import static com.def.GenericDef.PROC_IN_PROCESS;
import static com.def.GenericDef.PROC_WAIT;
import static com.def.GenericDef.RETURN_CODE_OK;
import static com.def.GenericDef.RETURN_CODE_SET_ERROR;
import static com.def.GenericDef.RETURN_CODE_UNKNOWN;
import static com.def.GenericDef.RETURN_MESG_OK;
import static com.def.GenericDef.TRX_OUT;
import static com.def.GenericDef.T_XPWIPRETAIN;
import static com.def.GenericDef.WIP_REATIN;
import static com.def.GenericDef._NO;
import static com.def.GenericDef._NORMAL;
import static com.def.GenericDef._YES;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.LockMode;
import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import com.dao.IRetBoxDao;
import com.dao.IRetPrdInfoDao;
import com.dao.IRetPrdLotDao;
import com.icim.service.ICIMBaseService;
import com.model.Ret_box;
import com.model.Ret_prd_info;
import com.model.Ret_prd_lot;
import com.model.Ret_prd_lotId;
import com.rtnBean.NotFoundRtnBeen;
import com.tx.Xpwipretain.XpwipretainI;
import com.tx.Xpwipretain.XpwipretainIA;
import com.tx.Xpwipretain.XpwipretainO;
import com.util.GUIDGenerator;
import com.util.MqOpe;
import com.util.Util;

@Scope("prototype")
@Service("XpwipretainService")
public class XpwipretainService extends ICIMBaseService{
	private static Logger logger = Logger.getLogger(XpwipretainService.class);
	private static String TX_NAME = T_XPWIPRETAIN;

	private XpwipretainI inTrx;
	private XpwipretainO outTrx;
	private MqOpe mqOpe;

	private String gszMsgBuf = "";
	private Timestamp gEvtTimestamp;
	private Double gEvtTimeD;
	private String gEvtSeqID;

	@Autowired
	private IRetBoxDao retBoxDao;
	@Autowired
	private IRetPrdInfoDao retPrdInfoDao;
	@Autowired
	private IRetPrdLotDao retPrdLotDao;
	
	public String subMainProc(String strInMsg) {
		Session session = retPrdInfoDao.getCrSession();

		long rtnCode = _NORMAL;
		String outMsg = null;
		gszMsgBuf = "";
		gEvtTimestamp = Util.getCurrentTimestamp();
		gEvtTimeD = Util.getDoubleTime();
		gEvtSeqID = GUIDGenerator.javaGUID();

		inTrx = new XpwipretainI();
		outTrx = new XpwipretainO();
		outTrx.setTrx_id(TX_NAME);
		outTrx.setType_id(TRX_OUT);
		outTrx.setRtn_code(String.valueOf(RETURN_CODE_SET_ERROR));
		mqOpe = new MqOpe();

		try {
			inTrx = (XpwipretainI) mqOpe.inStr2Obj(strInMsg, inTrx);
			logger.info("InTrx is " + strInMsg);

			rtnCode = subMainProc2(inTrx.getAction_flg().toCharArray()[0]);
			if (rtnCode != _NORMAL) {
				TransactionAspectSupport.currentTransactionStatus()
						.setRollbackOnly();
				outTrx.setRtn_code(String.valueOf(rtnCode));
				outTrx.setRtn_mesg(gszMsgBuf);
			} else {
				outTrx.setRtn_code(String.valueOf(RETURN_CODE_OK));
				outTrx.setRtn_mesg(RETURN_MESG_OK);
				session.flush();
			}
		} catch (Exception ex) {
			TransactionAspectSupport.currentTransactionStatus()
					.setRollbackOnly();
			outTrx.setRtn_mesg(ex.toString());
			outTrx.setRtn_code(RETURN_CODE_UNKNOWN);
			logger.error(Util.stackTraceToString(ex));
		} finally {
			outMsg = mqOpe.obj2Str(outTrx);
			logger.info(outMsg);
		}
		return outMsg;
	}

	private long subMainProc2(char actionType) {
		long lRc = _NORMAL;
		switch (actionType) {
		case 'R': {
			lRc = wipRrtain();
			break;
		}
		case 'C': {
			lRc = wipRetainCancel();
			break;
		}
		case 'A': {
			lRc = registLot();
			break;
		}
		case 'F': {
			lRc = registLotWholeBox();
			break;
		}
		case 'B': {
			lRc = registLotByBox();
			break;
		}
		case 'S': {
			lRc = wipRrtainSC();
			break;
		}
		case 'E': {
			lRc = wipRetainCancelSC();
			break;
		}
		default: {
			gszMsgBuf = "Invalide type input: [" + actionType + "]";
			return E_XPWIPRETAIN_INVALID_INPUT;
		}
		}

		return lRc;
	}

	/**
	 * Wip Retain
	 * 
	 * @return
	 */
	private long wipRrtain() {
		List<XpwipretainIA> iary = new ArrayList<XpwipretainIA>();
		Integer box_cnt = inTrx.getBox_cnt();
		iary = inTrx.getIary();
		for(int i=0;i<box_cnt;i++){
			String box_id = iary.get(i).getBox_id();
			Ret_box ret_box = new Ret_box();
			List<Ret_prd_info> ret_prd_infoList = new ArrayList<Ret_prd_info>();
			
			//获取箱子信息
			ret_box = retBoxDao.getWithLock(box_id, LockMode.UPGRADE);
			if (null == ret_box) {
				gszMsgBuf = new NotFoundRtnBeen(box_id, Ret_box.class).toString();
				return E_RET_BOX + E_READ_NOT_FOUND;
			}
			
			if (!PROC_EMPTY.equals(ret_box.getBox_stat())) {
				gszMsgBuf = "箱子 [" + ret_box.getBox_id() + "] " + "的状态为 ["
						+ ret_box.getBox_stat() + "],必须是" + PROC_EMPTY + "!";
				return E_XPWIPRETAIN_INVALID_BOX_STATUS;
			}
			
			if (!_NO.equals(ret_box.getReal_emp())) {
				gszMsgBuf = "箱子 [" + ret_box.getBox_id() + "] " + "的REAL_EMP标记为 ["
						+ ret_box.getReal_emp() + "],必须是" + _NO + "!";
				return E_XPWIPRETAIN_INVALID_REAL_EMP;
			}
			
			if (!_YES.equals(ret_box.getValid_flg())) {
				gszMsgBuf = "箱子 [" + ret_box.getBox_id() + "] " + "的VALID_FLG标记为 ["
				+ ret_box.getValid_flg() + "],必须是" + _YES + "!";
				return E_XPWIPRETAIN_INVALID_VALID_FLG;
			}
			
			if(WIP_REATIN.equals(ret_box.getBnk_flg())){
				gszMsgBuf = "箱子 [" + ret_box.getBox_id() + "] 已经处于在制保留状态！";
				return E_XPWIPRETAIN_INVALID_BNK_FLG;
			}
			//获取箱子中产品信息
			ret_prd_infoList = retPrdInfoDao.getShtListInfo(box_id);
			if (ret_prd_infoList != null) {
				for (Ret_prd_info prd : ret_prd_infoList) {
					if(!PROC_IN_PROCESS.equals(prd.getPrd_stat())){
						gszMsgBuf = "产品唯一码 [" + prd.getPrd_seq_id() 
						+ "]状态为["+prd.getPrd_stat()+"],必须为[INPR]！";
						return E_XPWIPRETAIN_INVALID_PRD_STATUS;
					}
					if(!BANK_OUT.equals(prd.getBnk_flg())){
						gszMsgBuf = "产品唯一码 [" + prd.getPrd_seq_id() + "] bnk_flg必须为[0]！";
						return E_XPWIPRETAIN_INVALID_BNK_FLG;
					}
					prd.setEvt_cate(EVT_WIP_RETAIN);
					prd.setEvt_usr(inTrx.getEvt_usr());
					prd.setEvt_timestamp(gEvtTimestamp);
					prd.setEvt_time_d(gEvtTimeD);
					prd.setEvt_seq_id(gEvtSeqID);
					prd.setBnk_flg(WIP_REATIN);
					retPrdInfoDao.update(prd);
				}
				ret_box.setBnk_flg(WIP_REATIN);
				ret_box.setEvt_cate(EVT_WIP_RETAIN);
				retBoxDao.update(ret_box);
			} else {
				gszMsgBuf = "箱子[" + box_id + "]中无玻璃！！！";
				return E_XPWIPRETAIN_NO_PRD_IN_BOX;
			}
		}
		return _NORMAL;
	}

	private long wipRrtainSC(){
		List<XpwipretainIA> iary = new ArrayList<XpwipretainIA>();
		iary = inTrx.getIary();
		for (int i=0;i<iary.size();i++){
			Ret_prd_info prd = retPrdInfoDao.get(iary.get(i).getPrd_seq_id());
			if (null == prd){
				gszMsgBuf = "玻璃[" + iary.get(i).getPrd_seq_id() + "]无记录！";
				return E_XPWIPRETAIN_NO_PRD_IN_BOX;
			}
			if(!PROC_IN_PROCESS.equals(prd.getPrd_stat())){
				gszMsgBuf = "产品唯一码 [" + prd.getPrd_seq_id() 
				+ "]状态为["+prd.getPrd_stat()+"],必须为[INPR]！";
				return E_XPWIPRETAIN_INVALID_PRD_STATUS;
			}
			if(!BANK_OUT.equals(prd.getBnk_flg())){
				gszMsgBuf = "产品唯一码 [" + prd.getPrd_seq_id() + "] bnk_flg必须为[0]！";
				return E_XPWIPRETAIN_INVALID_BNK_FLG;
			}
			prd.setEvt_cate(EVT_WIP_RETAIN);
			prd.setEvt_usr(inTrx.getEvt_usr());
			prd.setEvt_timestamp(gEvtTimestamp);
			prd.setEvt_time_d(gEvtTimeD);
			prd.setEvt_seq_id(gEvtSeqID);
			prd.setBnk_flg(WIP_REATIN);
			retPrdInfoDao.update(prd);
		}
		return _NORMAL;
	}
	
	/**
	 * Wip Retain Cancel
	 * 
	 * @return
	 */
	private long wipRetainCancel() {
		List<XpwipretainIA> iary = new ArrayList<XpwipretainIA>();
		Integer box_cnt = inTrx.getBox_cnt();
		iary = inTrx.getIary();
		for(int i=0;i<box_cnt;i++){
			String box_id = iary.get(i).getBox_id();
			Ret_box ret_box = new Ret_box();
			List<Ret_prd_info> ret_prd_infoList = new ArrayList<Ret_prd_info>();
			
			//获取箱子信息
			ret_box = retBoxDao.getWithLock(box_id, LockMode.UPGRADE);
			if (null == ret_box) {
				gszMsgBuf = new NotFoundRtnBeen(box_id, Ret_box.class).toString();
				return E_RET_BOX + E_READ_NOT_FOUND;
			}
			
			if (!PROC_EMPTY.equals(ret_box.getBox_stat())) {
				gszMsgBuf = "箱子 [" + ret_box.getBox_id() + "] " + "的状态为 ["
						+ ret_box.getBox_stat() + "], " + ",必须是" + PROC_EMPTY + "!";
				return E_XPWIPRETAIN_INVALID_BOX_STATUS;
			}
			
			if (!_NO.equals(ret_box.getReal_emp())) {
				gszMsgBuf = "箱子 [" + ret_box.getBox_id() + "] " + "的REAL_EMP标记为 ["
						+ ret_box.getReal_emp() + "], " + ",必须是" + _NO + "!";
				return E_XPWIPRETAIN_INVALID_REAL_EMP;
			}
			
			if (!_YES.equals(ret_box.getValid_flg())) {
				gszMsgBuf = "箱子 [" + ret_box.getBox_id() + "] " + "的VALID_FLG标记为 ["
				+ ret_box.getValid_flg() + "], " + ",必须是" + _YES + "!";
				return E_XPWIPRETAIN_INVALID_VALID_FLG;
			}
			
			if(!WIP_REATIN.equals(ret_box.getBnk_flg())){
				gszMsgBuf = "箱子 [" + ret_box.getBox_id() + "] " + "未处于在制保留状态！";
				return E_XPWIPRETAIN_INVALID_BOX_STATUS;
			}
			//获取箱子中产品信息
			ret_prd_infoList = retPrdInfoDao.getShtListInfo(box_id);
			if (!ret_prd_infoList.isEmpty()) {
				for (Ret_prd_info prd : ret_prd_infoList) {
					if(!PROC_IN_PROCESS.equals(prd.getPrd_stat())){
						gszMsgBuf = "产品唯一吗 [" + prd.getPrd_seq_id() 
						+ "]状态为["+prd.getPrd_stat()+"],必须为[INPR]！";
						return E_XPWIPRETAIN_INVALID_PRD_STATUS;
					}
					if(Util.isSpaceCheck(prd.getLot_id())){
						gszMsgBuf = "产品唯一吗 [" + prd.getPrd_seq_id() 
						+ "]批次为空，请先登记批次信息！";
						return E_XPWIPRETAIN_NO_LOT;
					}
					prd.setEvt_cate(EVT_WIP_RETAIN_CANCEL);
					prd.setEvt_usr(inTrx.getEvt_usr());
					prd.setEvt_timestamp(gEvtTimestamp);
					prd.setEvt_time_d(gEvtTimeD);
					prd.setEvt_seq_id(gEvtSeqID);
					prd.setBnk_flg(BANK_OUT);
					retPrdInfoDao.update(prd);
				}
				ret_box.setBnk_flg(BANK_OUT);
				ret_box.setEvt_cate(EVT_WIP_RETAIN_CANCEL);
				retBoxDao.update(ret_box);
			} else {
				gszMsgBuf = "箱子[" + box_id + "]中无玻璃！！！";
				return E_XPWIPRETAIN_NO_PRD_IN_BOX;
			}
		}
		return _NORMAL;
	}
	
	private long wipRetainCancelSC(){
		List<XpwipretainIA> iary = new ArrayList<XpwipretainIA>();
		iary = inTrx.getIary();
		for (int i=0;i<iary.size();i++){
			Ret_prd_info prd = retPrdInfoDao.get(iary.get(i).getPrd_seq_id());
			if (null != prd){
				if(!PROC_IN_PROCESS.equals(prd.getPrd_stat())){
					gszMsgBuf = "产品唯一吗 [" + prd.getPrd_seq_id() 
					+ "]状态为["+prd.getPrd_stat()+"],必须为[INPR]！";
					return E_XPWIPRETAIN_INVALID_PRD_STATUS;
				}
				if(Util.isSpaceCheck(prd.getLot_id())){
					gszMsgBuf = "产品唯一吗 [" + prd.getPrd_seq_id() 
					+ "]批次为空，请先登记批次信息！";
					return E_XPWIPRETAIN_NO_LOT;
				}
				prd.setEvt_cate(EVT_WIP_RETAIN_CANCEL);
				prd.setEvt_usr(inTrx.getEvt_usr());
				prd.setEvt_timestamp(gEvtTimestamp);
				prd.setEvt_time_d(gEvtTimeD);
				prd.setEvt_seq_id(gEvtSeqID);
				prd.setBnk_flg(BANK_OUT);
				retPrdInfoDao.update(prd);
			}
		}
		return _NORMAL;
	}
	
	/**
	 * regist Lot when WIP Retain Cancel
	 * 
	 * @return
	 */
	private long registLot() {
		long rtnCode = _NORMAL;
		Ret_prd_info ret_prd_info = new Ret_prd_info();
		ret_prd_info = retPrdInfoDao.getWithLock(inTrx.getPrd_seq_id(), LockMode.UPGRADE);
		if(!Util.isSpaceCheck(ret_prd_info.getLot_id())){
			gszMsgBuf = "产品唯一码[" + inTrx.getPrd_seq_id() + "]已绑定批次号，请确认！";
			return E_XPWIPRETAIN_ALREADY_LOT;
		}
		ret_prd_info.setLot_id(inTrx.getLot_id());
		ret_prd_info.setLot_splt_id(LOT_SPLIT_0);
		ret_prd_info.setEvt_cate(EVT_REGIST_LOT);
		ret_prd_info.setEvt_usr(inTrx.getEvt_usr());
		ret_prd_info.setEvt_timestamp(gEvtTimestamp);
		ret_prd_info.setEvt_time_d(gEvtTimeD);
		ret_prd_info.setEvt_seq_id(gEvtSeqID);
		retPrdInfoDao.update(ret_prd_info);
		
		rtnCode = addLotInfo(ret_prd_info);
		if (rtnCode != _NORMAL) {
			return rtnCode;
		}
		
		return _NORMAL;
	}
	
	/**
	 * regist Lot when WIP Retain Cancel
	 * 
	 * @return
	 */
	private long registLotWholeBox() {
		long rtnCode = _NORMAL;
		String sql = "FROM Ret_prd_info where box_id_fk = '" + inTrx.getBox_id() + "'";
		List<Ret_prd_info> prd_list = new ArrayList<Ret_prd_info>();
		prd_list = retPrdInfoDao.find(sql);
		if (!prd_list.isEmpty()){
			for (Ret_prd_info prd:prd_list){
				if("".equals(prd.getLot_id()) || prd.getLot_id() == null){
					prd.setLot_id(inTrx.getLot_id());
					prd.setLot_splt_id(LOT_SPLIT_0);
					prd.setEvt_cate(EVT_REGIST_LOT);
					prd.setEvt_usr(inTrx.getEvt_usr());
					prd.setEvt_timestamp(gEvtTimestamp);
					prd.setEvt_time_d(gEvtTimeD);
					prd.setEvt_seq_id(gEvtSeqID);
					retPrdInfoDao.update(prd);
					
					rtnCode = addLotInfo(prd);
					if (rtnCode != _NORMAL) {
						return rtnCode;
					}
				}
			}
		}else {
			gszMsgBuf = "箱子中没有玻璃或都已绑定批次号！";
			return E_XPWIPRETAIN_ALREADY_LOT;
		}
		return _NORMAL;
	}
	/**
	 * Add lot info
	 * 
	 * @return
	 */
	private long addLotInfo(Ret_prd_info ret_prd_info) {
		
		Ret_prd_lot ret_prd_lot = new Ret_prd_lot();
		Ret_prd_lotId ret_prd_lotId = new Ret_prd_lotId();
		ret_prd_lotId.setLot_id(inTrx.getLot_id());
		ret_prd_lotId.setLot_splt_id(LOT_SPLIT_0);

		ret_prd_lot = retPrdLotDao.get(ret_prd_lotId);
		if (null != ret_prd_lot) {
			/**
			 * 检查内部订单是否相符
			 */
			if(!ret_prd_lot.getWo_id_fk().equals(ret_prd_info.getWo_id_fk())){
				gszMsgBuf = "批次[" + ret_prd_lotId.getLot_id() + "]的内部订单["+ret_prd_lot.getWo_id_fk()+
							"]与产品的内部订单["+ret_prd_info.getWo_id_fk()+"]不符，请确认！";
				return E_XPWIPRETAIN_WO_UNMATCH;
			}
			ret_prd_lot.setLot_qty(ret_prd_lot.getLot_qty() + 1);
			ret_prd_lot.setEvt_usr(inTrx.getEvt_usr());
			ret_prd_lot.setEvt_timestamp(gEvtTimestamp);
			ret_prd_lot.setEvt_time_d(gEvtTimeD);

			retPrdLotDao.update(ret_prd_lot);
		} else {
//			gszMsgBuf = "未找到批次[" + ret_prd_lotId + "]的信息，请确认！";
//			return E_RET_PROD_LOT + E_READ_NOT_FOUND;
			ret_prd_lot = new Ret_prd_lot();
			ret_prd_lotId = new Ret_prd_lotId();
			ret_prd_lotId.setLot_id(inTrx.getLot_id());
			ret_prd_lotId.setLot_splt_id(LOT_SPLIT_0);
			ret_prd_lot.setId(ret_prd_lotId);
			ret_prd_lot.setLot_stat(PROC_WAIT);
			ret_prd_lot.setLot_qty(1);
			ret_prd_lot.setWo_id_fk(ret_prd_info.getWo_id_fk());

			ret_prd_lot.setEvt_usr(inTrx.getEvt_usr());
			ret_prd_lot.setEvt_timestamp(gEvtTimestamp);
			ret_prd_lot.setEvt_time_d(gEvtTimeD);
			ret_prd_lot.setStb_timestamp(gEvtTimestamp);

			retPrdLotDao.save(ret_prd_lot);
		}

		return _NORMAL;
	}

	
	/**
	 * regist Lot when WIP Retain Cancel
	 * 
	 * @return
	 */
	private long registLotByBox() {
		Integer prdQty = 0;
		List<Ret_prd_info> gRet_prd_infoList = new ArrayList<Ret_prd_info>();
		gRet_prd_infoList = retPrdInfoDao.getShtListInfo(inTrx.getBox_id());
		if (null != gRet_prd_infoList) {
			for(int k = 0; k < gRet_prd_infoList.size(); k++){
				if(Util.isSpaceCheck(gRet_prd_infoList.get(k).getLot_id())){
					gRet_prd_infoList.get(k).setLot_id(inTrx.getLot_id());
					gRet_prd_infoList.get(k).setLot_splt_id(LOT_SPLIT_0);
					gRet_prd_infoList.get(k).setEvt_cate(EVT_REGIST_LOT);
					gRet_prd_infoList.get(k).setEvt_usr(inTrx.getEvt_usr());
					gRet_prd_infoList.get(k).setEvt_timestamp(gEvtTimestamp);
					gRet_prd_infoList.get(k).setEvt_time_d(gEvtTimeD);
					gRet_prd_infoList.get(k).setEvt_seq_id(gEvtSeqID);
					retPrdInfoDao.update(gRet_prd_infoList.get(k));
					prdQty ++;
				}
			}
			
			Ret_prd_lot ret_prd_lot = new Ret_prd_lot();
			Ret_prd_lotId ret_prd_lotId = new Ret_prd_lotId();
			ret_prd_lotId.setLot_id(inTrx.getLot_id());
			ret_prd_lotId.setLot_splt_id(LOT_SPLIT_0);
			ret_prd_lot = retPrdLotDao.get(ret_prd_lotId);
			if (null != ret_prd_lot) {
				ret_prd_lot.setLot_qty(ret_prd_lot.getLot_qty() + prdQty);
				ret_prd_lot.setEvt_usr(inTrx.getEvt_usr());
				ret_prd_lot.setEvt_timestamp(gEvtTimestamp);
				ret_prd_lot.setEvt_time_d(gEvtTimeD);

				retPrdLotDao.update(ret_prd_lot);
			} else {
				ret_prd_lot = new Ret_prd_lot();
				ret_prd_lotId = new Ret_prd_lotId();
				ret_prd_lotId.setLot_id(inTrx.getLot_id());
				ret_prd_lotId.setLot_splt_id(LOT_SPLIT_0);
				ret_prd_lot.setId(ret_prd_lotId);
				ret_prd_lot.setLot_stat(PROC_WAIT);
				ret_prd_lot.setLot_qty(prdQty);

				ret_prd_lot.setEvt_usr(inTrx.getEvt_usr());
				ret_prd_lot.setEvt_timestamp(gEvtTimestamp);
				ret_prd_lot.setEvt_time_d(gEvtTimeD);
				ret_prd_lot.setStb_timestamp(gEvtTimestamp);

				retPrdLotDao.save(ret_prd_lot);
			}
		}
		return _NORMAL;
	}
}
